import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.*;

public class CaminhoVlc {
	public static String type = "HOST";
	public static JLabel vlc = new JLabel();
	public static JButton mudarVlc = new JButton("Mudar Caminho do VLC");	
	public static JButton ok = new JButton("Ok");	
	JFrame frame = new JFrame("Teste");
	GridBagConstraints c = new GridBagConstraints(); 
	GridBagLayout grid = new GridBagLayout();
	public void abrir(){
		try {
	        BufferedReader in = new BufferedReader(new FileReader("VLC.txt"));
	        VlcReceptor.vlcpath = in.readLine();
	        in.close();
	    } catch (IOException e) {
	    	VlcReceptor.vlcpath = "erro no caminho";
	    }
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		frame.setBounds(30, 30, 300, 300);
		Container content = frame.getContentPane(); // Get the content pane
		content.setLayout(grid);// Set the container layout mgr
	    			//cria os botoes
		vlc.setText("o caminho para seu vlc eh : " + VlcReceptor.vlcpath);
		mudarVlc.addActionListener(new Caminho());
		ok.addActionListener(new Pronto());
		c.gridx = 0;
	    c.gridy = 0;
		content.add(ok,c);
		c.gridx = 2;
	    c.gridy = 0;
		content.add(mudarVlc,c);
		c.gridx = 1;
	    c.gridy = 1;
		content.add(vlc,c);
		frame.pack();
		frame.setVisible(true);
	}
	
	private class Caminho implements ActionListener{
		public Arquivos arq = new Arquivos();
		public void actionPerformed (ActionEvent e){
			File caminho = arq.pegarArquivo();
	    	try {
	    		new File("VLC.txt").delete();
				FileWriter writer = new FileWriter("VLC.txt",true);
				writer.write(caminho.getPath());
				writer.close();
				VlcReceptor.vlcpath = caminho.getPath();
				vlc.setText("o caminho para seu vlc eh : " + VlcReceptor.vlcpath);
			} catch (IOException e1) {
				e1.printStackTrace();
			} 
			}
	}
	
	private class Pronto implements ActionListener{
		public void actionPerformed (ActionEvent e){
			VlcReceptor.vlc = new VLCControler(VlcReceptor.vlcpath);
			frame.dispose();
		}
	}
}
 